import { Component } from 'react';
import './PrSon.scss';
import { globalContext } from './global';
class PcSon extends Component {
  static contextType = globalContext;
  state = {};
  changeName = () => {
    this.context.updateName('孙组件修改了全局变量');
  };
  render() {
    console.log(this, '孙组件');
    const { name, email } = this.context;
    return (
      <div className="son">
        <h1>子组件2的son，父组件的孙</h1>
        <h2>
          孙组件获取爷组件的数据（通过thisContext调用）：{name}---{email}
          <br />
          <button onClick={this.changeName}>修改全局变量</button>
        </h2>
      </div>
    );
  }
}

export default PcSon;
